import { getDictModel } from '@/api/goodsManagement'
import { APILX } from '@/api/requestLx'

export let goodsColumns = [
  {
    title: '物品编号',
    key: 'serialNumber',
    dataIndex: 'serialNumber'
  },
  {
    title: '物品名称',
    key: 'serialName',
    dataIndex: 'serialName',
    width: '13%'
    // isrequired: true,
    // type: FormTypes.slot,
    // slotName: 'processCodeName',
  },
  {
    title: '规格',
    key: 'serialSpecifications',
    dataIndex: 'serialSpecifications',
    width: '13%'
    // isrequired: true,
    // type: FormTypes.slot,
    // slotName: 'processCodeName',
  },
  {
    title: '物品属性',
    key: 'unitName',
    dataIndex: 'serialProperties',
    width: '13%'
    // isrequired: true,
    // type: FormTypes.slot,
    // slotName: 'processCodeName',
  },
  {
    title: '单位',
    key: 'unitName',
    dataIndex: 'unitName',
    width: '13%'
    // isrequired: true,
    // type: FormTypes.slot,
    // slotName: 'processCodeName',
  }

]
export let columns = [
  {
    title: '物品编号',
    dataIndex: 'serialNumber',
    ellipsis: true,
    // fixed: 'left',
    width: 200,
    searchIndex: 'serialNumber',
    scopedSlots: {
      filterDropdown: 'searchDropdown',
      filterIcon: 'searchIcon',
      customRender: 'serialNumber'
    }
  },
  {
    title: '物品名称',
    dataIndex: 'serialName',
    ellipsis: true,
    // fixed: 'left',
    width: 180,
    searchIndex: 'serialName',
    options: [],
    scopedSlots: {
      filterDropdown: 'searchDropdown',
      filterIcon: 'searchIcon',
      customRender: 'serialName'
    }
  },
  {
    title: '规格',
    dataIndex: 'serialSpecifications',
    ellipsis: true,
    // fixed: 'left',
    width: 180,
    searchIndex: 'serialSpecifications',
    options: [],
    scopedSlots: {
      filterDropdown: 'searchDropdown',
      filterIcon: 'searchIcon',
      customRender: 'serialSpecifications'
    }
  },
  {
    title: '单位',
    dataIndex: 'unitName',
    ellipsis: true,
    // fixed: 'left',
    width: 180,
    // searchIndex: 'unitName',
    // options: [],
    scopedSlots: {
      // filterDropdown: 'selectPeople',
      // filterIcon: 'dateIcon',
      customRender: 'unitName'
    }
  },
  // {
  //   title: '备注',
  //   dataIndex: 'remark',
  //   ellipsis: true,
  //   // fixed: 'left',
  //   width: 180,
  //   searchIndex: 'remark',
  //   options: [],
  //   scopedSlots: {
  //     // filterDropdown: 'searchDropdown',
  //     // filterIcon: 'searchIcon',
  //     // customRender: 'remark',
  //   },
  // },
  {
    title: '物品属性',
    dataIndex: 'serialPropertiesName',
    ellipsis: true,
    width: 180,
    searchIndex: 'serialProperties',
    options: [],
    scopedSlots: {
      filterDropdown: 'selectDropdown',
      filterIcon: 'dateIcon',
      customRender: 'serialPropertiesName'
    }
  },
  {
    title: '出入数量',
    dataIndex: 'inWarehouseNum',
    ellipsis: true,
    width: 180,
    searchIndex: 'inWarehouseNum',
    sorter: true,
    scopedSlots: {
      // filterDropdown: 'selectDropdown',
      // filterIcon: 'dateIcon',
      // customRender: 'startTimeCreate',
    }
  },
  {
    title: '出入库时间',
    dataIndex: 'warehouseTime',
    ellipsis: true,
    width: 180,
    searchIndex: 'warehouseTime',
    sorter: true,

    scopedSlots: {
      // filterDropdown: 'selectPeople',
      // filterIcon: 'dateIcon',
      // customRender: 'warehouseTime',
    }
  },
  {
    title: '单据类型',
    dataIndex: 'inOutTypeName',
    ellipsis: true,
    width: 180,
    searchIndex: 'inOutType',
    options: [],
    scopedSlots: {
      filterDropdown: 'selectDropdown',
      filterIcon: 'dateIcon',
      customRender: 'inOutTypeName'
    }
  },
  {
    title: '出入库编号',
    dataIndex: 'entryCode',
    ellipsis: true,
    width: 180,
    searchIndex: 'entryCode',
    scopedSlots: {
      // filterDropdown: 'selectPeople',
      // filterIcon: 'dateIcon',
      customRender: 'entryCode'
    }
  },
  {
    title: '出入库类型',
    dataIndex: 'warehouseTypeName',
    ellipsis: true,
    width: 180,
    searchIndex: 'warehouseType',
    options: [],

    scopedSlots: {
      filterDropdown: 'selectDropdown',
      filterIcon: 'dateIcon',
      customRender: 'warehouseTypeName'
    }
  },
  {
    title: '领送人',
    dataIndex: 'persionName',
    ellipsis: true,
    width: 180,
    searchIndex: 'persion',
    scopedSlots: {
      // filterDropdown: 'selectPeople',
      // filterIcon: 'dateIcon',
      customRender: 'persionName'
    }
  },
  {
    title: '最小库存',
    dataIndex: 'inventoryMin',
    ellipsis: true,
    width: 180,
    searchIndex: 'inventoryMin',
    sorter: true,
    scopedSlots: {
      // filterDropdown: 'selectPeople',
      // filterIcon: 'dateIcon',
      customRender: 'inventoryMin'
    }
  },
  {
    title: '最大库存',
    dataIndex: 'inventoryMax',
    ellipsis: true,
    width: 180,
    searchIndex: 'inventoryMax',
    sorter: true,
    scopedSlots: {
      // filterDropdown: 'selectPeople',
      // filterIcon: 'dateIcon',
      customRender: 'inventoryMax'
    }
  },
  {
    title: '当前库存',
    dataIndex: 'inventoryNum',
    ellipsis: true,
    width: 180,
    searchIndex: 'inventoryNum',
    scopedSlots: {
      // filterDropdown: 'selectPeople',
      // filterIcon: 'dateIcon',
      // customRender: 'inventoryNum',
    }
  },
  {
    title: '工艺路线',
    dataIndex: 'processRouteName',
    ellipsis: true,
    width: 180,
    searchIndex: 'processRouteName',
    scopedSlots: {
      // filterDropdown: 'selectPeople',
      // filterIcon: 'dateIcon',
      // customRender: 'processRouteName',
    }
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    ellipsis: true,
    width: 180,
    searchIndex: 'createTime',
    sorter: true,
    scopedSlots: {
      // filterDropdown: 'datePicker',
      // filterIcon: 'dateIcon',
      customRender: 'createTime'
    }
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    ellipsis: true,
    width: 180,
    sorter: true,
    searchIndex: 'updateTime',
    scopedSlots: {
      // filterDropdown: 'datePicker',
      // filterIcon: 'dateIcon',
      customRender: 'updateTime'
    }
  },
  {
    title: '创建人',
    dataIndex: 'createByName',
    ellipsis: true,
    width: 180,
    searchIndex: 'createBy',
    scopedSlots: {
      filterDropdown: 'createBy',
      filterIcon: 'dateIcon',
      customRender: 'createByName'
    }
  },
  {
    title: '更新人',
    dataIndex: 'updateByName',
    ellipsis: true,
    width: 180,
    searchIndex: 'updateBy',
    scopedSlots: {
      filterDropdown: 'updateBy',
      filterIcon: 'dateIcon',
      customRender: 'updateByName'
    }
  }

]
export let allColumn = [
  ...columns
]

export function getTypeList(num) {
  let parameters = { dictCode: 'SERIAL_PROPERTIES' }
  console.log('columns', columns)
  console.log('')
  getDictModel(parameters).then((res) => {
    if (res.code == 200) {
      let goodAttribute = JSON.parse(JSON.stringify(res.result)).map((item) => {
        return {
          label: item.title,
          key: item.value
        }
      })
      columns[4].options = goodAttribute
      allColumn[4].options = goodAttribute

      if (num) {
        columns[num].options = goodAttribute
        allColumn[num].options = goodAttribute
      }
    }
    // this.$store.commit('SET_CURRENT_PREFIX', '/jksaas-easyMake/easyMake')
  })
  let types = [
    {
      label: '出库',
      key: 1
    },
    {
      label: '入库',
      key: 0
    }
  ]
  columns[7].options = types
  allColumn[7].options = types

  let inWarehouseType = []
  APILX.warehouseEntryInfoEntryType().then((res) => {
    inWarehouseType = res.result.map(item => {
      return {
        label: item.itemText,
        key: item.itemValue
      }
    })
  })
  let outWarehouseType = []
  APILX.warehouseOutboundOrderInfoEntryType().then((res) => {
    outWarehouseType = res.result.map(item => {
      return {
        label: item.itemText,
        key: item.itemValue
      }
    })
    console.log(inWarehouseType, 'outWarehouseType')
    // columns[9].options = [...outWarehouseType, ...inWarehouseType]
    // allColumn[9].options = [...outWarehouseType, ...inWarehouseType]
    columns.forEach(item => {
      if (item.dataIndex == 'warehouseTypeName') {
        item.options = [...outWarehouseType, ...inWarehouseType]
      }
    })
    allColumn.forEach(item => {
      if (item.dataIndex == 'warehouseTypeName') {
        item.options = [...outWarehouseType, ...inWarehouseType]
      }
    })
  })
}
